﻿<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.Master" CodeBehind="Admin.aspx.cs" Inherits="AirPortSystem.Administration.Admin" %>

<%@ Register Src="~/Controls/DateTimePicker.ascx" TagPrefix="sphene" TagName="DateTimePicker" %>

<asp:Content ID="AdminContent" ContentPlaceHolderID="MainContent" runat="server">
    <asp:UpdatePanel runat="server">
        <ContentTemplate>
            <asp:DropDownList runat="server"
                ID="DropDownListFromAirport"
                AutoPostBack="true"
                AppendDataBoundItems="true"
                SelectMethod="DropDownListFromAirport_GetData">
                <asp:ListItem Text="--Select start point--" Value="" />
            </asp:DropDownList>
        </ContentTemplate>
    </asp:UpdatePanel>

    <asp:UpdatePanel runat="server">
        <ContentTemplate>
            <asp:DropDownList runat="server"
                ID="DropDownListEndPoint"
                AutoPostBack="true"
                AppendDataBoundItems="true"
                SelectMethod="DropDownListToAirport_GetData">
                <asp:ListItem Text="--Select end point--" Value="" />
            </asp:DropDownList>
        </ContentTemplate>
    </asp:UpdatePanel>

    <asp:UpdatePanel runat="server">
        <ContentTemplate>
            <asp:GridView
                runat="server"
                ID="GridViewFlightsAdmin"
                ItemType="AirPortSystem.Models.Flight"
                AutoGenerateColumns="false"
                DataKeyNames="Id"
                SelectMethod="GridViewFlightsAdmin_GetData"
                UpdateMethod="GridViewFlightsAdmin_UpdateItem"
                DeleteMethod="GridViewFlightsAdmin_DeleteItem"
                AllowSorting="true"
                AutoGenerateEditButton="true"
                AutoGenerateDeleteButton="true"
                AllowPaging="true"
                PageSize="10"
                ShowFooter="true"
                CssClass="table table-striped table-bordered table-condensed">
                <Columns>
                    <asp:TemplateField HeaderText="From Airport" SortExpression="FromAirPort">
                        <ItemTemplate>
                            <%#: Item.FromAirPort %>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox runat="server" ID="TextBoxFromAirPort" Text="<%# BindItem.FromAirPort %>" />
                        </EditItemTemplate>
                        <FooterTemplate>
                            <asp:TextBox runat="server" ID="TextBoxFromAirPort" />
                        </FooterTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="To airport" SortExpression="ToAirPort">
                        <ItemTemplate>
                            <%#: Item.ToAirPort %>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox runat="server" ID="TextBoxToAirPort" Text="<%# BindItem.ToAirPort %>" />
                        </EditItemTemplate>
                        <FooterTemplate>
                            <asp:TextBox runat="server" ID="TextBoxToAirPort" />
                        </FooterTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Flight date" SortExpression="FlightDate">
                        <ItemTemplate>
                            <%#: String.Format("{0:dd-MMM-yyyy HH:mm}", Item.FlightDate) %>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox runat="server" ID="TextBoxFlightDate" Text="<%# BindItem.FlightDate %>" />
                        </EditItemTemplate>
                        <FooterTemplate>
                            <sphene:DateTimePicker runat="server" ID="DateTimePicker" />
                        </FooterTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Available Tickets" SortExpression="AvailableTickets">
                        <ItemTemplate>
                            <%#: Item.AvailableTickets %>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox runat="server" ID="TextBoxAvailableTickets" Text="<%# BindItem.AvailableTickets %>" />
                        </EditItemTemplate>
                        <FooterTemplate>
                            <asp:TextBox runat="server" ID="TextBoxAvailableTickets" />
                        </FooterTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Price" SortExpression="Price">
                        <ItemTemplate>
                            <%#: Item.Price %>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox runat="server" ID="TextBoxPrice" Text="<%# BindItem.Price %>" />
                        </EditItemTemplate>
                        <FooterTemplate>
                            <asp:TextBox runat="server" ID="TextBoxPrice" />
                        </FooterTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField>
                        <ItemTemplate>
                        </ItemTemplate>
                        <FooterTemplate>
                            <asp:Button Text="Add" ID="ButtonAddFlight" OnClick="ButtonAddFlight_Click" runat="server" CssClass="btn" />
                        </FooterTemplate>
                    </asp:TemplateField>
                </Columns>
                <EmptyDataTemplate> 
                    <tr>
                        <th scope="col">From airport</th>
                        <th scope="col">To airport</th>
                        <th scope="col">Fly date</th>
                        <th scope="col">Available Tickets</th>
                        <th scope="col">Price</th>
                        <th scope="col"></th>
                    </tr>
                    <tr>
                        <td>
                            <asp:TextBox ID="TextBoxFromAirPort" runat="server" /></td>
                        <td>
                            <asp:TextBox ID="TextBoxToAirPort" runat="server" /></td>
                        <td>
                            <asp:TextBox ID="TextBoxFlightDate" runat="server" /></td>
                        <td>
                            <asp:TextBox ID="TextBoxAvailableTickets" runat="server" /></td>
                        <td>
                            <asp:TextBox ID="TextBoxPrice" runat="server" /></td>
                        <td>
                            <asp:Button Text="Add" ID="ButtonAddFlight" OnClick="ButtonAddFlight_Click" runat="server" /></td>
                    </tr>
                </EmptyDataTemplate>
            </asp:GridView>

            <asp:ValidationSummary runat="server" ShowModelStateErrors="true" CssClass="text-warning" DisplayMode="SingleParagraph" />
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
